<?

//Initiate Authenticate
SecurityRedirect ();



//initiate Vars
define("PRIMARY_KEY","tucode");
$KEY[]         = array("PRIMARY_KEY"=>PRIMARY_KEY);
$FileName      = "ais_transaction_memoex.php";
$FileTemplate  = "ais_transaction_memoex_list.html";
$TableName     = "ais_gainloss_status";
$SubHeaderTitle= "Transaction Exchange Gain/Loss - Memorial Exchange";
$PageSize      = 10 ;
$HTMLGridList  = "MemorialExGrid";
//************ FORM ACTION **************
//None


//Initiate Database Table For Search;
$FCode = GetParam("transnoSearch","");

//******* DATABASE FORM QUERY ***********
$SQL = "SELECT * FROM `$TableName` ";
$SQLCount = "SELECT count(*) FROM `$TableName` ";

//$SQL = $SQL.$WHERE." ORDER BY gainloss_id ";

//Retrieve Parameter from search
if ($FCode) {
    $CustomWhere = " nomp like '".$FCode."%'";
    if (strlen($WHERE)) $WHERE .= " AND ".$CustomWhere;
    else $WHERE = $CustomWhere;
}
if (strlen($WHERE)) {
    $SQL  = $SQL."WHERE ".$WHERE. " ORDER BY gainloss_id";
    $SQLCount .= "WHERE ".$WHERE;
}

//echo "$SQL"; exit;

//print $SQL;
//******* SHOW FORM CONTENT *********
$PageNum = 1;
$result = mysql_query($SQL);
$RecCnt = mysql_num_rows($result);


if (GetParam("PageNum","")) $PageNum  = GetParam("PageNum","");

$TBS = new clsTinyButStrong ;
$TBS->LoadTemplate($MOD_TEMPLATE_DIR."/".$FileTemplate);
$TBS->MergeBlock("bln",$KEY);
$TBS->MergeBlock("blg",$DBMysql,$SQL,$PageSize,$PageNum,$RecCnt);
$TBS->MergeNavigationBar('nv',array('size'=>10,'pos'=>'centred'),$PageNum,$RecCnt,$PageSize) ;
$TBS->Show();


function DeleteRecord ($sequence_name,$PageSize) {
    global $DBConnection,$FileName,$TableName;
        if (GetParam("PageNum","")) {
          $StartRecord = GetParam("PageNum","")*$PageSize-$PageSize+1;
          $EndRecord   = $StartRecord+$PageSize-1;

        }
    for ($x=$StartRecord;$x<=$EndRecord;$x++) {
        if (GetParam($sequence_name.$x,"")) {
            $DBConnection->Delete("$TableName",$sequence_name.$x);
        }
    }
    header("Location: $FileName");
    exit;

}





function FormSave ($table, $keyField, $FormFields, $SpecialCase="", $PrimaryKey) {
        global $FileName, $MaxGrid, $DBConnection;
        $TotalData = $MaxGrid * 2;
        $NewDataStart = GetParam("NewData","0");
        $NewDataStart = 1;

        for ($a=1;$a<=$TotalData;$a++) {
            if (!GetParam("txtCheck".$a,"")) {
                foreach ($FormFields as $key=>$formatting) {
                        if (!GetParam($keyField.$a,"")) {
                                print GetParam($keyField.$a,"");
                                $EndOfData = 1;
                                break;
                        }
                        $value = GetParam($key.$a,"");
                        if ($formatting=="number") $value = str_replace(",","",$value);
                        if ($formatting=="date") {
                                list($day,$month,$year) = explode("/",$value);
                                $value = "$year-$month-$day";
                    }
                        $DBConnection->add_data($table,$key,$value);
                }

                $rate = StrToNumber(GetParam("rate",""));
                $jmh  = StrToNumber(GetParam("jumlah".$a,""));

                // Add by Chandra (15 May 2009)
                $cash_type = GetParam("cash_type","");
                //var_dump($cash_type); exit;
                if($cash_type) $DBConnection->add_data($table,'cash_type',$cash_type);
                // end update

                $rupiah = $rate * $jmh;
                $DBConnection->add_data($table,"rupiah",$rupiah);
                if ($EndOfData) {
                        break;
            }
                if (strlen($SpecialCase)) {
                        foreach ($SpecialCase as $key => $value) {
                        //        print "add_data($table,$key,$value);<br>";
                                $DBConnection->add_data($table,$key,$value);
                        }
                }
//                print "$a < $NewDataStart<br>";
                if ($a < $NewDataStart) {
                         if (strlen($PrimaryKey)) {
                            $DBConnection->UpdateGrid($PrimaryKey,GetParam($PrimaryKey.$a,""));
                          } else {
                            $DBConnection->UpdateGrid($keyField,GetParam($keyField.$a,""));
                     }
                } else {
                        $DBConnection->InsertGrid();
//                        $DBConnection->dbc->debug();
            }
            }
        }
        $DBConnection->ClearData();
}

function m_event_blg ($BlockName,&$CurrRec,&$DetailSrc,$RecNum) {
    global $FileName;

        if (ereg("MP",$CurrRec["nobkt"]) && ereg("BK|BB|ND",$CurrRec["noref"])) {
            $CurrRec["jumlah"] = $CurrRec["jumlah"]*-1;
        }

        if ($CurrRec["jumlah"]<0)
        $CurrRec["jumlah"] = "(".FormatNumber($CurrRec["jumlah"]*-1,2).")";
}

?>
